﻿namespace PlaylistCopy.Services.Impl
{
    using System.IO;
    using CuttingEdge.Conditions;

    internal class FileService : IFileService
    {
        public void Copy(string source, string target, bool overwrite)
        {
            Condition.Requires(source, "source").IsNotNullOrEmpty();
            Condition.Requires(target, "target").IsNotNullOrEmpty();

            File.Copy(source, target, overwrite);
        }

        public bool Exists(string source)
        {
            Condition.Requires(source, "source").IsNotNull();

            return File.Exists(source);
        }

        public string FileExtension(string fileName)
        {
            Condition.Requires(fileName, "fileName").IsNotNullOrWhiteSpace();

            return Path.GetExtension(fileName);
        }

        public StreamWriter WriteFile(string fileName, FileMode fileMode)
        {
            var fileStream = new FileStream(fileName, fileMode);
            return new StreamWriter(fileStream);
        }
    }
}
